package com.bwie.controller;

import com.bwie.mapper.TbJpMapper;
import com.bwie.pojo.TbJp;
import com.bwie.service.TbJpService;
import com.bwie.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author:Max
 * @Date: 2024/8/9 19:00
 * @Description
 **/
@RestController
@RequestMapping("/user/index")
@Slf4j
public class UserController {
    @Autowired
    TbJpService tbJpService;

    @Autowired
    TbJpMapper tbJpMapper;

    /**
     * 获取列表
     */
    @PostMapping("/list")
    public R list(){
        List<TbJp> tbJps = tbJpMapper.selectList(null);
        log.info("列表获取成功");
        return R.OK(tbJps);
    }


    /**
     * 新增
     */
    @PostMapping("/addList")
    public R addList(@RequestBody TbJp tbJp){
       tbJpMapper.insert(tbJp);
       log.info("插入成功");
        return R.OK();
    }


    /**
     * 修改
     */
    @PostMapping("/updateList")
    public R updateList(@RequestBody TbJp tbJp){
        tbJpMapper.updateById(tbJp);
        log.info("修改成功");
        return R.OK();
    }

    /**
     * 删除
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Integer id){
        tbJpMapper.deleteById(id);
        log.info("删除成功"+new Date());
        return R.OK();
    }
}
